home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / cli / bb2cli.lha / BBgoesCLI / BB2File.asm < prev    next >
Encoding:
Assembly Source File  |  1992-09-02  |  4.6 KB  |  211 lines

  1.  
  2. **********************************************************
  3. *          BB2File v1.0              22.12.1994          *
  4. **********************************************************
  5. * copyright (c) 1994 by Jens Tröger, all rights reserved *
  6. *               this is Public Domain                    *
  7. **********************************************************
  8. *        written using HiSoft`s DevPac 3.04              *
  9. * greets fly to Oliver Reiff, "PackMAN" Falk Zühlsdorff  *
  10. * "Janosh" Jan Stötzer, Jan van den Baard,...            *
  11. **********************************************************
  12. * (non)sense: this will read the Bootblock from a given  *
  13. * floppy-drive and then write to an file for later use   *
  14. * works with KS1.2 and better                            *
  15. * USAGE: BB2File <unit> <file>                           *
  16. **********************************************************
  17.  
  18.     opt    o+,p+ 
  19.  
  20.     move.l    a0,a5 
  21.  
  22. ; ----- alloc memory for bootblock and several structures 
  23.  
  24. alloc_mem    move.l    4.w,a6 
  25.     move.l    #1024+88,d0    ; Bootblock + Port/IO... 
  26.     move.l    #$10001,d1 
  27.     jsr    -198(a6)        ; _LVOAllocMem 
  28.     move.l    d0,a4        ; a4: PTR to mem
  29.      beq    exit 
  30.  
  31. ; -----  open dos.library
  32.  
  33. open_dos    lea    dosname(pc),a1 
  34.     moveq    #33,d0 
  35.     jsr    -552(a6)        ; _LVOOpenLibrary 
  36.     move.l    d0,d6        ; d6: DOSBase
  37.     beq    free_mem 
  38.  
  39. ; -----  get unit 
  40.  
  41. read_unit    cmp.b    #"d",(a5)+ 
  42.     bne    usage 
  43.     cmp.b    #"f",(a5)+ 
  44.     bne    usage 
  45.     moveq    #0,d0 
  46.     move.b    (a5)+,d0 
  47.     sub.b    #48,d0 
  48.     cmp.b    #4,d0 
  49.     bge    usage
  50.     cmp.b    #0,d0
  51.     blt    usage
  52.     move.l    d0,d2         ; d2: Unit 
  53.     cmp.b    #":",(a5)+ 
  54.     bne    usage
  55.     adda.l    #1,a5
  56.     move.l    a5,a0 
  57. .loop    cmp.b    #10,(a0)+
  58.     bne.s    .loop
  59.     move.b    #0,-(a0)
  60.  
  61. ; -----  add MessagePort to system
  62.  
  63. add_port    sub.l    a1,a1 
  64.     jsr    -294(a6)        ; _LVOFindTask 
  65.     move.l    d0,1024+16(a4) 
  66.     lea    1024(a4),a1
  67.     jsr    -354(a6)        ; _LVOAddPort 
  68.  
  69. ; -----  open trackdisk.device 
  70.  
  71. open_track    lea    trackname(pc),a0 
  72.     lea    1024+32(a4),a1    ; a1: DiskIO-Struc 
  73.     move.l    d2,d0 
  74.     moveq    #0,d1 
  75.     jsr    -444(a6)        ; _LVOOpenDevice 
  76.     tst.l    d0 
  77.     bne    err_nodev        ; FATAL !!!!!
  78.  
  79. ; -----  read bootblock 
  80.  
  81. read_bb    lea    1024+46(a4),a0    ; a0: RepPort 
  82.     lea           1024(a4),a1    ; a1: ReplyPort-Struc 
  83.     move.l    a1,(a0) 
  84.     lea    1024+32(a4),a1    ; a1: DiskIO-Struc 
  85.     move.w    #2,28(a1) 
  86.     move.l    #1024,36(a1) 
  87.     move.l    a4,40(a1) 
  88.     move.l    #0,44(a1) 
  89.     jsr    -456(a6)        ; _LVODoIO 
  90.     move.l    d0,d2
  91.     move    #9,28(a1) 
  92.     move.l    #0,36(a1) 
  93.     jsr    -456(a6)        ; _LVODoIO 
  94.     tst.l    d2
  95.     bne.s    err_nodoio
  96.  
  97. ; -----  close trackdisk.device 
  98.  
  99. close_dev    lea     1024+32(a4),a1    ; a1: DiskIO-Struc 
  100.     jsr    -450(a6)        ; _LVOCloseDevice 
  101.  
  102. ; -----  remove port 
  103.  
  104. rem_port    lea    1024(a4),a1    ; a1: ReplyPort 
  105.     jsr    -360(a6)        ; _LVORemPort 
  106.  
  107. ; -----  open file 
  108.  
  109. open_file    move.l    d6,a6 
  110.     move.l    #1006,d2        ; MODE: NEW_FILE 
  111.     move.l    a5,d1
  112.     jsr    -30(a6)        ; _LVOOpen
  113.     move.l    d0,d7        ; d7: File-Handle 
  114.      beq.s    no_open 
  115.  
  116. ; -----  write
  117.  
  118. write    move.l    d7,d1
  119.     move.l    a4,d2
  120.     move.l    #1024,d3
  121.     jsr    -48(a6)        ; _LVOWrite
  122.     cmp.l    #1024,d0
  123.     bne.s    no_write
  124.  
  125. ; -----  close up clearly
  126.  
  127. close_file    move.l    d7,d1
  128.     jsr    -36(a6)        ; _LVOClose  
  129.  
  130. ; -----  close dos.library
  131.  
  132. close_dos    move.l    4.w,a6 
  133.     move.l    d6,a1 
  134.     jsr    -414(a6)        ; _LVOCloseLibrary 
  135.  
  136. ; -----  free allocated memory 
  137.  
  138. free_mem    move.l    a4,a1 
  139.     move.l    #1024+88,d0 
  140.     jsr    -210(a6)        ; _LVOFreeMem 
  141.  
  142. ; -----  returncode: 0 
  143.  
  144. exit    moveq    #0,d0 
  145.     rts 
  146.  
  147. ; -----  several messages
  148.  
  149. usage    lea    usage_text(pc),a2 
  150.     move.l    #usage_text_end-usage_text,d3 
  151.     bsr.s    write_msg 
  152.     bra    close_dos 
  153.  
  154. err_nodev    lea    err1_text(pc),a2 
  155.     moveq    #38,d3 
  156.     bsr.s    write_msg
  157.     move.l    4.w,a6
  158.     lea    1024(a4),a1    ; a1: ReplyPort 
  159.     jsr    -360(a6)        ; _LVORemPort 
  160.     bra.s    close_dos
  161.  
  162. err_nodoio    lea    err2_text(pc),a2 
  163.     moveq    #44,d3 
  164.     bsr.s    write_msg
  165.     move.l    4.w,a6
  166.     lea     1024+32(a4),a1    ; a1: DiskIO-Struc 
  167.     jsr    -450(a6)        ; _LVOCloseDevice 
  168.      lea    1024(a4),a1    ; a1: ReplyPort 
  169.     jsr    -360(a6)        ; _LVORemPort 
  170.     bra.s    close_dos
  171.  
  172. no_open    lea    err3_text(pc),a2 
  173.     moveq      #25,d3 
  174.     bsr.s    write_msg 
  175.     bra    close_dos 
  176.  
  177. no_write    lea    err4_text(pc),a2 
  178.     moveq    #37,d0 
  179.     bsr.s    write_msg 
  180.     bra.s    close_file 
  181.  
  182. ; -----  write text to stdout
  183.  
  184. write_msg    move.l    d6,a6 
  185.     jsr    -60(a6)        ; _LVOOutput 
  186.     move.l    d0,d1 
  187.     move.l    a2,d2 
  188.     jmp    -48(a6)        ; _LVOWrite 
  189.  
  190. ; -----  names, texts
  191.  
  192. dosname    dc.b    "dos.library",0 
  193.     even 
  194. trackname    dc.b    "trackdisk.device",0 
  195.     even 
  196. err1_text    dc.b    "FATAL ERROR opening trackdisk.device.",10 
  197.     even 
  198. err2_text    dc.b    "Error reading Bootblock. No disk inserted ?",10 
  199.     even 
  200. err3_text    dc.b    "Cannot open Output-File.",10 
  201.     even 
  202. err4_text    dc.b    "Error writing to File. Aborting.",10 
  203.     even
  204. usage_text    dc.b    10,$9b,"1mBB2File v1.0",$9b,"0m 1994 by Jens Tröger",10 
  205.     dc.b    "USAGE: BB2File <unit> <file>",10 
  206.     dc.b    "Where <unit> is one of your mounted floppies (df0:) "
  207.     dc.b    "and <file> is the Path/Name of the file.",10,10 
  208. usage_text_end 
  209.  
  210.     end 
  211.